/**
 * ************************************************************************
 *
 * @file    BuildTime.c
 * @brief   编译时间转换
 * @author  负号科技(fuhaokj@foxmail.com)
 * @version 0.1
 * @date    2023-08-18
 *
 * ************************************************************************
 *   __       _                 _    _
 *  / _|     | |               | |  (_)
 * | |_ _   _| |__   __ _  ___ | | ___
 * |  _| | | | '_ \ / _` |/ _ \| |/ / |
 * | | | |_| | | | | (_| | (_) |   <| |
 * |_|  \__,_|_| |_|\__,_|\___/|_|\_\ |
 *                                 _/ |
 *                                |__/
 *
 * @copyright Copyright (c) 2023 负号科技
 * For study and research only, no reprinting
 * ************************************************************************
 */
#include "BuildTime.h"

const uint8_t str_date[12] = __DATE__;
const uint8_t str_time[8] = __TIME__;

//REVISION_TIME_TypeDef Build_Time;

/**
 * @brief   编译时间
 * @date    2023-08-18
 *
 */
void ObtainBuildTime(BUILD_TIME_TYPE_DEF *bt)
{
    uint8_t month;

    switch (str_date[2])
    {
    case 'n':                               // Jan和jun
        month = str_date[1] == 'a' ? 1 : 6; // 判断1月还是6月
        break;

    case 'b': // Feb
        month = 2;
        break;

    case 'r':                               // Mart和Apr
        month = str_date[1] == 'a' ? 3 : 4; // 判断3月还是4月
        break;

    case 'y': // May
        month = 5;
        break;

    case 'l': // Jul
        month = 7;
        break;

    case 'g': // Aug
        month = 8;
        break;

    case 'p': // Sep
        month = 9;
        break;

    case 't':         // Oct
        month = 0x0A; // 10
        break;

    case 'v':         // Nov
        month = 0x0B; // 11
        break;

    case 'c':         // Dec
        month = 0x0C; // 12
        break;
    }

    bt->month = month;

    bt->year = (str_date[7] - '0') * 1000;
    bt->year += (str_date[8] - '0') * 100;
    bt->year += (str_date[9] - '0') * 10;
    bt->year += str_date[10] - '0';

    if (str_date[4] == 32)
    {
        bt->day = str_date[5] - '0';
    }
    else
    {
        bt->day = (str_date[4] - '0') * 10;
        bt->day += str_date[5] - '0';
    }

    bt->hour = (str_time[0] - '0') * 10;
    bt->hour += str_time[1] - '0';
    bt->minute = (str_time[3] - '0') * 10;
    bt->minute += str_time[4] - '0';
    bt->secode = (str_time[6] - '0') * 10;
    bt->secode += str_time[7] - '0';
}
